﻿using System;
using System.IO;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Project;

namespace Microsoft.WowAddonStudio.Project
{
	/// <summary>
	/// An object that deals with user interaction via a GUI in the form a hierarchy: a parent node with zero or more child nodes, each of which
	/// can itself be a hierarchy.  
	/// </summary>
	public class WowFolderNode : FolderNode
	{
		/// <summary>
		/// Initializes a new instance of the <see cref="WowFolderNode"/> class.
		/// </summary>
		/// <param name="root">The root.</param>
		/// <param name="path">The path.</param>
		/// <param name="element">The element.</param>
		public WowFolderNode(ProjectNode root, string path, ProjectElement element)
			: base(root, path, element)
		{
		}

		/// <summary>
		/// Rename Folder
		/// </summary>
		/// <param name="label">new Name of Folder</param>
		/// <returns>VSConstants.S_OK, if succeeded</returns>
		public override int SetEditLabel(string label)
		{
			var oldName = Path.GetFileName(Url.TrimEnd('\\'));
			if (String.Compare(oldName, label, StringComparison.Ordinal) == 0)
			{
				// Label matches current Name
				return VSConstants.S_OK;
			}

			// if label matches current name with different casing
			if (String.Compare(oldName, label, StringComparison.OrdinalIgnoreCase) == 0)
			{
				string tempLabel = Guid.NewGuid().ToString();
				base.SetEditLabel(tempLabel);
			}

			return base.SetEditLabel(label);
		}
	}
}